package com.jinzhi.eventresource.controller;

import com.jinzhi.common.utils.Result;
import com.jinzhi.eventresource.dao.JzPermission;
import com.jinzhi.eventresource.main.EventresourceAllocationDO;
import com.jinzhi.eventresource.service.IJzPermissionService;
import com.jinzhi.eventresource.vo.PermissionResourceListVO;
import com.jinzhi.eventresource.vo.PermissionSaveVO;
import com.jinzhi.jzweb.domain.resourceLibrary.SecretKey;
import com.jinzhi.jzweb.service.resourceLibrary.SecretKeyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IJzPermissionService jzPermissionService;
    @Autowired
    private SecretKeyService secretKeyService;

    // list @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
    @GetMapping("/list")
    public Result list(String userId) {
        return Result.ok(jzPermissionService.list(userId));
    }

    // listresource
    @GetMapping("/listResource")
    public Result listresource() {
        Map<String, List<PermissionResourceListVO>> permissionResourceListVOS = jzPermissionService.resourceList();
        return Result.ok(permissionResourceListVOS);
    }

    // detail
    @GetMapping("/detail")
    public Result detail(JzPermission jzPermission) {
        return Result.ok(jzPermissionService.delete(jzPermission));
    }

    // save
    @PostMapping("/save")
    public Result save(@RequestBody PermissionSaveVO permissionSaveVO) {
        return Result.ok(jzPermissionService.save(permissionSaveVO));
    }

//    @PostMapping("/batchSave")
//    public Object batchSave(@RequestBody List<JzPermission> jzPermissionList){
//        return Result.ok(jzPermissionService.batchSave(jzPermissionList));
//    }


    // update
    @GetMapping("/update")
    public Result update(JzPermission jzPermission) {
        return Result.ok(jzPermissionService.update(jzPermission));
    }

    // delete
    @DeleteMapping("/delete")
    public Result delete(@RequestBody JzPermission jzPermission) {
        return Result.ok(jzPermissionService.delete(jzPermission));
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestBody List<JzPermission> jzPermissionList) {
        return Result.ok(jzPermissionService.batchDelete(jzPermissionList));
    }

    @GetMapping()
    @RequiresPermissions("jzweb:permission:permission")
    String permission() {
        return "eventresource/eventresourceModule/eventresourceModule";
    }


    @GetMapping("/add")
    @RequiresPermissions("jzweb:permission:permission")
    String add() {
        return "eventresource/eventresourceModule/eventresourceModule";
    }

    @GetMapping("/remove")
    @RequiresPermissions("jzweb:permission:permission")
    String remove() {
        return "eventresource/eventresourceModule/eventresourceModule";
    }

    @GetMapping("/edit")
    @RequiresPermissions("jzweb:permission:permission")
    String edit() {
        return "eventresource/eventresourceModule/eventresourceModule";
    }

}
